package com.fy.fyspace.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StrUtilsTO {

    //创建一个静态方法，用户传入一个邮箱，就会截取邮箱的前部分和后部分分别返回给用户，比如：1234@qq.com会返回1234和@qq.com
    public static String[] splitEmail(String email) {
        String[] result = new String[2];
        Pattern pattern = Pattern.compile("@");
        Matcher matcher = pattern.matcher(email);
        if (matcher.find()) {
            result[0] = email.substring(0, matcher.start());
            result[1] = email.substring(matcher.end());
        }
        return result;
    }

    //创建一个冒泡排序算法，用户输入层数，获取结果
    public static int[] bubbleSort(int[] arr) {
        int temp = 0;
        for (int i = 0, n = arr.length; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        return arr;
    }


}
